package com.example.computer_exam_training_sys.service.impl;

import com.example.computer_exam_training_sys.entity.adminlogsInfo;
import com.example.computer_exam_training_sys.mapper.admin_logsMapper;
import com.example.computer_exam_training_sys.service.admin_logsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class admin_logsServiceImpl implements admin_logsService {

    @Autowired
    private admin_logsMapper mapper;

    @Override
    public List<adminlogsInfo> findAll(Integer adminId, String operationType) {
        return mapper.findAll(adminId, operationType);
    }

    @Override
    public List<String> getOperationTypes() {
        return mapper.getOperationTypes();
    }

    @Override
    public String generateCsv(List<adminlogsInfo> logs) {
        return logs.stream()
                .map(log -> String.join(",", log.getLogId().toString(), log.getAdminId().toString(),
                        log.getOperationType(), log.getOperationDetail(), log.getIpAddress(),
                        log.getCreateTime().toString()))
                .collect(Collectors.joining("\n"));
    }

    @Override
    public int addLog(adminlogsInfo log) {
        return mapper.addLog(log);
    }

    @Override
    public int deleteLog(Integer logId) {
        return mapper.deleteLog(logId); // 实现删除日志的方法
    }
}